import logging
import os

import allure
from utils.data_preprocessor import dddd_ocr_text
from utils.data_preprocessor import get_res_sn_text


@allure.step("1. 解析请求数据")
def analyse_case(case):
    method = case["method"]
    # url = BASE_URL + case["path"]

    # if case["is_mock"]:
    #     url = os.environ["MOCK_URL"] + case["path"]
    # else:
    #     url = os.environ["URL"] + case["path"]

    url = os.environ["MOCK_URL"] + case["path"] if case["is_mock"] else os.environ["URL"] + case["path"]
    # url = os.environ["URL"] + case["path"]
    headers = eval(case["headers"]) if isinstance(case["headers"], str) else None
    params = eval(case["params"]) if isinstance(case["params"], str) else None
    data = eval(case["data"]) if isinstance(case["data"], str) else None
    json = eval(case["json"]) if isinstance(case["json"], str) else None
    files = eval(case["files"]) if isinstance(case["files"], str) else None

    request_data = {
        "method": method,
        "url": url,
        "headers": headers,
        "params": params,
        "data": data,
        "json": json,
        "files": files
    }

    logging.info(f"1. 解析请求数据，解析数据为:{request_data}")
    allure.attach(f"{request_data}", name = "解析数据结果")

    return request_data